/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */

#ifndef __QS_MainWindow_H__
#define __QS_MainWindow_H__

#include "Prerequisites.h"

#include "ProjectDialog.h"

#include "PortfolioWidget.h"
#include "TransactionViewWidget.h"
#include "StockScreenerWidget.h"
#include "AssetsAnalyzeDialog.h"


namespace QSThink
{
	//Root window of the application
	class MainWindow : 
		public QMainWindow
	{
		Q_OBJECT
	public:
		static const int PROPERTY_DOCK_WIDTH=220;
		static const int ASSETS_DOCK_WIDTH=220;

		static const QString HIERACHY_WIDGET_NAME;
		static const QString OBJECT_CREATE_WIDGET_NAME;
		static const QString ASSET_WIDGET_NAME;
		
	public:
		MainWindow(QWidget *parent = 0, Qt::WFlags flags = 0);
		~MainWindow();
		
		void createDefaultUI();//load ui when project created or opened
		void showTrayMessage(const QString &title, const QString &msg, QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information, int msecs = 10000);

	protected:
		void closeEvent(QCloseEvent *event);
		void createSystemTray()
		{
			minimizeAction = new QAction(tr("Mi&nimize"), this);
			connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));

			maximizeAction = new QAction(tr("Ma&ximize"), this);
			connect(maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized()));

			restoreAction = new QAction(tr("&Restore"), this);
			connect(restoreAction, SIGNAL(triggered()), this, SLOT(restoreWindow()));

			quitAction = new QAction(tr("&Quit"), this);
			connect(quitAction, SIGNAL(triggered()), this, SLOT(sendQuit()));

			QIcon icon("qt.png");

			_trayIconMenu = new QMenu(this);
			_trayIconMenu->addAction(minimizeAction);
			_trayIconMenu->addAction(maximizeAction);
			_trayIconMenu->addAction(restoreAction);
			_trayIconMenu->addSeparator();
			_trayIconMenu->addAction(quitAction);

			_trayIcon = new QSystemTrayIcon(this);
			_trayIcon->setIcon(icon);
			_trayIcon->setContextMenu(_trayIconMenu);

			_trayIcon->show();
			connect(_trayIcon, SIGNAL(messageClicked()), this, SLOT(messageClicked()));
			connect(_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
				this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));

			setWindowIcon(icon);
		}
	
		QSystemTrayIcon* _trayIcon;
		QMenu* _trayIconMenu;
		QAction* minimizeAction;
		QAction* maximizeAction;
		QAction* restoreAction;
		QAction* quitAction;

	public slots:
		void sendQuit();

		void selectCreateDialog();
		void selectOpenDialog();
		void saveProject();
		void dowloadData();
		void iconActivated(QSystemTrayIcon::ActivationReason reason);
		void messageClicked();
		void restoreWindow();

		//change style slots
		void WindowsXPStyle();
		void MotifStyle();
		void CDEStyle();
		void PlastiqueStyle();
		void CleanlooksStyle();


		//analyze slots
		void assetAnalyze();

		
		
	private:
		void createMenus();

		void createPropertyDock();
		void createAssetsDock();
		void createObjectDock();
		void createHierachyDock();

		//************************************
		//Create our portfolio widget.
		//************************************
		void createPortfolioWidget();//main
		void createTransactionViewWidget();
		void createScreenerWidget();
		void createTextEditWidget();
		void createSearchWidget();
		void createDepositWidget();
		void createTransactionDownloadWidget();
		void createFilterWidget();
	protected:
		QTabWidget* _mainTab;
		QDockWidget *_dock0;
		QDockWidget *_dock1;
		QDockWidget *_dock2;
		QDockWidget *_dock3;

		
		PortfolioWidget* _portfolioWidget;
		TransactionViewWidget* _transactionViewWidget;
		StockScreenerWidget* _stockScreenerWidget;

		ProjectDialog* _projectDialog;
		AssetsAnalyzeDialog* _assetsAnalyzeDialog;
		
	};
}

#endif
